package cn.buhler.thread;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class DefaultThreadFactory implements ThreadFactory {
	private final AtomicInteger threadNumber = new AtomicInteger(1);
	private final String namePrefix;

	public DefaultThreadFactory(String poolName) {
		namePrefix = poolName + "-thread-";
	}

	@Override
	public Thread newThread(Runnable r) {
		Thread thread = new Thread(r, namePrefix + threadNumber.getAndIncrement());
		thread.setDaemon(false); // 设置为非守护线程
		thread.setPriority(Thread.NORM_PRIORITY); // 设置线程优先级为普通优先级
		return thread;
	}
}